package com.dubious.interview.euler;

import java.math.BigInteger;

public class Problem16 {

    /**
     * 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
     * 
     * What is the sum of the digits of the number 21000?
     * 
     * @param args
     */
    public static void main(String[] args) {
        // initial reaction is to use BigInteger to calculate this
        BigInteger base = BigInteger.valueOf(2);
        BigInteger result = base.pow(1000);

        String resultAsString = result.toString(10);
        int sum = 0;
        for (int i = 0; i < resultAsString.length(); i++) {
            sum += Integer.parseInt(resultAsString.substring(i, i + 1));
        }

        System.out.println("Sum of digits of 2^1000: " + sum);
    }
}
